/*
 * Copyright (C) 2005-present, 58.com.  All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.swak.mmap;

import lombok.Getter;

/**
 * append data result
 */
@Getter
public class AppendResult {
	// Return code
	private final AppendStatus status;
	// Where to start writing
	private final long wroteOffset;
	// Write Bytes
	private final int wroteBytes;
	// Message storage timestamp
	private final long storeTimestamp;

	public AppendResult(AppendStatus status) {
		this(status, 0, 0, -1L);
	}

	public AppendResult(AppendStatus status, long wroteOffset, int wroteBytes, long storeTimestamp) {
		this.status = status;
		this.wroteOffset = wroteOffset;
		this.wroteBytes = wroteBytes;
		this.storeTimestamp = storeTimestamp;
	}

	public boolean isOk() {
		return this.status == AppendStatus.PUT_OK;
	}

	@Override
	public String toString() {
		return "AppendDataResult [status=" + status + ", wroteOffset=" + wroteOffset + ", wroteBytes=" + wroteBytes
				+ ", storeTimestamp=" + storeTimestamp + "]";
	}
}
